package demo1;

//购票，并发问题
public class TestThread4 implements Runnable {
    private int trickNums = 10;

    @Override
    public void run() {
        while (true) {
            if (trickNums <= 0) {
                break;
            }
            try {
                Thread.sleep(20);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "抢到了" + trickNums-- + "票");
        }
    }

    public static void main(String[] args) {
        TestThread4 thread4 = new TestThread4();
        new Thread(thread4, "小明").start();
        new Thread(thread4, "老王").start();
        new Thread(thread4, "黄牛").start();
    }
}
